package com.baidu.automata.core.flow.steps;

import org.apache.log4j.Logger;

import com.baidu.automata.core.flow.BaseOpStep;
import com.baidu.automata.core.type.FloatField;
import com.baidu.automata.core.type.LongField;

public class JudgingErrorRateStep extends BaseOpStep {
	private final static Logger logger = Logger.getLogger("flow_Platform");
	
	private FloatField stdRate = null;

	public FloatField getStdRate() {
		return stdRate;
	}

	public void setStdRate(FloatField stdRate) {
		this.stdRate = stdRate;
	}

	@Override
	protected int execute() {
		LongField rowNumField = (LongField) this.getDataFieldById("row_num");
		LongField failedNumField = (LongField) this.getDataFieldById("failed_num");

		logger.info(String.format("error rate:%s", stdRate.getValue()));
		
		if (((double)failedNumField.getValue().longValue() / (double)rowNumField.getValue().longValue()) > stdRate.getValue().floatValue()) {
			return 1;
		} else {
			return 0;
		}
	}
}
